import { getTableData, downloadExcel } from '@/services/analysisApi'
import { robotGetRobotList } from '@/services/overviewRobots';
export default {
    namespace: 'sameOperateAnalysis',
    state: {},
    effects: {
        *getTableData({ payload, callback }, { call, put }) {
            const response = yield call(getTableData, payload);
            if (response) {
                if (callback && typeof callback === 'function') {
                    callback(response);
                }
                yield put({
                    type: 'search',
                    payload: response,
                });
            }
        },
        *robotGetRobotList({ payload, callback }, { call, put }) { // 根据用户名获取robotlist
            const response = yield call(robotGetRobotList, payload);
            if (response) {
              if (callback && typeof callback === 'function') {
                callback(response);
              }
              yield put({
                type: 'search',
                payload: response,
              });
            }
          },
        *downloadExcel({ payload, callback }, { call, put }) {
            const response = yield call(downloadExcel, payload);
            if (response) {
                if (callback && typeof callback === 'function') {
                    callback(response);
                }
                yield put({
                    type: 'download',
                    payload: response,
                });
            }
        }
    },

    reducers: {
        search(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
        download(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        }
    }
}